<template>
    <mescroll-uni
        ref="mescrollRef"
        @init="mescrollInit"
        :height="height"
        :down="downOption"
        @down="downRefresh"
        :up="upOption"
        @up="getData">
        <view class="header"
            ><text>您当天任务需前往{{ recordAmout }}个取货点取货</text></view
        >

        <!-- <task-item v-for="(item,index) in datas" :type="type" :key="index" :data="item"></task-item> -->
        <task-item :data="datas"></task-item>
    </mescroll-uni>
</template>

<script>
import { mapGetters } from "vuex"
import taskItem from "@/components/task/task-item.vue"
// import {
// 	GetStoreOrderPage
// } from "@/service/api/reservation.js"
export default {
    components: {
        taskItem,
    },
    props: {
        height: {
            type: String,
            default: "100px",
        },
        type: {
            type: Number,
            default: 1,
        },
    },
    computed: {
        ...mapGetters(["getUpbookingView"]),
    },
    watch: {
        //监听更新
        getUpbookingView(e) {
            this.downRefresh()
        },
    },
    data() {
        return {
            datas: [],
            data: [],
            productList: [],
            param: {},
            downOption: {
                use: true,
            },
            dayTimes: "",
            recordAmout: 0,
        }
    },
    mounted() {
        if (this.type == 1) {
            let date = new Date()
            let year = date.getFullYear()
            let mon = date.getMonth() + 1
            mon = mon > 9 ? mon : "0" + mon
            let day = date.getDate()
            day = day > 9 ? day : "0" + day
            this.dayTimes = `${year}-${mon}-${day}`
        }
        this.refresh()
    },
    methods: {
        //获取列表数据
        getData(page) {
            let param = this.param
            param.pageSize = page.size
            param.pageIndex = page.num
            param.type = this.type
            if (this.dayTimes) {
                param.dayTimes = this.dayTimes
            }
            GetStoreOrderPage(param).then((res) => {
                if (res.State && res.Data) {
                    this.mescroll.endBySize(res.Data.length, res.RecordAmout)
                    this.datas = this.datas.concat(res.Data)
                    this.recordAmout = res.RecordAmout
                }
            })
        },
        //刷新
        refresh() {
            this.downRefresh()
        },
        //刷新
        downRefresh() {
            this.datas = []
            this.mescroll.resetUpScroll()
        },
        openFilterDate() {
            this.$emit("filterDate", "")
        },
        update(date) {
            if (this.type == 1) {
                this.dayTimes = date
                this.refresh()
            }
        },
    },
}
</script>

<style lang="scss">
.header {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    margin-bottom: $app-page-padding;
    padding-top: $app-page-padding;
    .time {
        padding: 6rpx 20rpx;
        border-radius: 26rpx;
        border: 1px solid red;
    }
}
</style>
